//
//  BaseChirldViewController.m
//  JRTTDemo
//
//  Created by 赵 on 2018/2/6.
//  Copyright © 2018年 袁书辉. All rights reserved.
//

#import "BaseChirldViewController.h"

@interface BaseChirldViewController ()
{
    UIScrollView * _scrollView;
}

@end

@implementation BaseChirldViewController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addRefresh];
    
    
}


-(void)addRefresh
{
    UIScrollView * scrollView = [self getScrollViewAddRefreshAndFooter];
    if (scrollView) {
        _scrollView = scrollView;
        __weak typeof(self) weakSelf = self;
        scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf loadData];
        }];
        
        scrollView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
            [weakSelf loadMore];
        }];
        
        [scrollView.mj_header beginRefreshing];
    }
   
    
    [self addObserver:self forKeyPath:@"dataArray" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
    
    
}

-(UIScrollView * )getScrollViewAddRefreshAndFooter
{
    return nil;
}

-(void)loadData
{
    [PPNetworkHelper GET:@"http://is.snssdk.com/api/news/feed/v79/?list_count=0&refer=1&count=20&min_behot_time=1517904460&last_refresh_sub_entrance_interval=1517908034&loc_mode=7&loc_time=1517907980&latitude=29.533803&longitude=106.561917&city=%E9%87%8D%E5%BA%86%E5%B8%82&tt_from=pull&lac=13150&cid=42682&plugin_enable=3&iid=25504462036&device_id=43911586446&ac=wifi&channel=huawei&aid=13&app_name=news_article&version_code=659&version_name=6.5.9&device_platform=android&ab_version=275263%2C276222%2C271178%2C208278%2C252767%2C249828%2C246859%2C275644%2C268839%2C276183%2C249686%2C249675%2C264842%2C268794%2C249667%2C274584%2C206075%2C249674%2C272432%2C229304%2C276049%2C270947%2C271842%2C275587%2C275947%2C266386%2C271717%2C260441%2C240865%2C274670%2C270388%2C276002%2C251713%2C271059%2C274344%2C275066%2C229399%2C276128%2C270333%2C275347%2C276296%2C267093%2C274411%2C270107%2C258356%2C247848%2C264452%2C276394%2C249045%2C271663%2C276246%2C244746%2C273961%2C274292%2C264616%2C275350%2C268788%2C260656%2C261944%2C241181%2C268341%2C232362%2C265709%2C271194%2C273233%2C239096%2C272011%2C170988%2C269425%2C273499%2C268663%2C275295%2C276351%2C243585%2C276203%2C272515%2C272486%2C257280%2C261294%2C265122%2C258603&ab_client=a1%2Cc4%2Ce1%2Cf2%2Cg2%2Cf7&ab_feature=94563%2C102749&abflag=3&ssmix=a&device_type=BAC-AL00&device_brand=HUAWEI&language=zh&os_api=24&os_version=7.0&uuid=866432038206049&openudid=50468f33e8fc72cf&manifest_version_code=659&resolution=720*1208&dpi=320&update_version_code=65902&_rticket=1517908034070&plugin=10575&fp=42TqLlm1Pr5_FlHtLrU1FlFSF2Qq&pos=5r_-9Onkv6e_dBoQeCcbeCUfv7G_8fLz-vTp6Pn4v6esrauzqKuspKyqsb_x_On06ej5-L-nr6SzqK6upa2u4A%3D%3D&rom_version=emotionui_5.1_bac-al00c00b180&ts=1517908034&as=a2d5e787f2640a60692679&mas=006f960b27a6d1556135f1ecd4ed19fe54c2a4528da0225a82&cp=55a67c9679042q1" parameters:@{
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @"category":self.tModel111.category
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      } success:^(id responseObject) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          [_scrollView.mj_header endRefreshing];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          DataModel * model = [DataModel yy_modelWithJSON:responseObject];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           [self.dataArray setArray:model.data];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          [self updateUI];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      } failure:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                       [_scrollView.mj_header endRefreshing];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 }];
    
    
    
}

-(void)loadMore
{
    
    [PPNetworkHelper GET:@"http://is.snssdk.com/api/news/feed/v79/?list_count=0&refer=1&count=20&min_behot_time=1517904460&last_refresh_sub_entrance_interval=1517908034&loc_mode=7&loc_time=1517907980&latitude=29.533803&longitude=106.561917&city=%E9%87%8D%E5%BA%86%E5%B8%82&tt_from=load_more&lac=13150&cid=42682&plugin_enable=3&iid=25504462036&device_id=43911586446&ac=wifi&channel=huawei&aid=13&app_name=news_article&version_code=659&version_name=6.5.9&device_platform=android&ab_version=275263%2C276222%2C271178%2C208278%2C252767%2C249828%2C246859%2C275644%2C268839%2C276183%2C249686%2C249675%2C264842%2C268794%2C249667%2C274584%2C206075%2C249674%2C272432%2C229304%2C276049%2C270947%2C271842%2C275587%2C275947%2C266386%2C271717%2C260441%2C240865%2C274670%2C270388%2C276002%2C251713%2C271059%2C274344%2C275066%2C229399%2C276128%2C270333%2C275347%2C276296%2C267093%2C274411%2C270107%2C258356%2C247848%2C264452%2C276394%2C249045%2C271663%2C276246%2C244746%2C273961%2C274292%2C264616%2C275350%2C268788%2C260656%2C261944%2C241181%2C268341%2C232362%2C265709%2C271194%2C273233%2C239096%2C272011%2C170988%2C269425%2C273499%2C268663%2C275295%2C276351%2C243585%2C276203%2C272515%2C272486%2C257280%2C261294%2C265122%2C258603&ab_client=a1%2Cc4%2Ce1%2Cf2%2Cg2%2Cf7&ab_feature=94563%2C102749&abflag=3&ssmix=a&device_type=BAC-AL00&device_brand=HUAWEI&language=zh&os_api=24&os_version=7.0&uuid=866432038206049&openudid=50468f33e8fc72cf&manifest_version_code=659&resolution=720*1208&dpi=320&update_version_code=65902&_rticket=1517908034070&plugin=10575&fp=42TqLlm1Pr5_FlHtLrU1FlFSF2Qq&pos=5r_-9Onkv6e_dBoQeCcbeCUfv7G_8fLz-vTp6Pn4v6esrauzqKuspKyqsb_x_On06ej5-L-nr6SzqK6upa2u4A%3D%3D&rom_version=emotionui_5.1_bac-al00c00b180&ts=1517908034&as=a2d5e787f2640a60692679&mas=006f960b27a6d1556135f1ecd4ed19fe54c2a4528da0225a82&cp=55a67c9679042q1" parameters:@{
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       @"category":self.tModel111.category
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       } success:^(id responseObject) {
                                                                                                       [_scrollView.mj_footer endRefreshing];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      DataModel * model = [DataModel yy_modelWithJSON:responseObject];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           [self.dataArray addObjectsFromArray:model.data];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           [self updateUI];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       } failure:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                         [_scrollView.mj_footer endRefreshing];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       }];
}

-(void)updateUI
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
